import 'dart:async';

import 'package:elephant_fish/model/user_info_entity.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class SlideBanner extends StatefulWidget {
  final PhotoWall photoWall;

  const SlideBanner({Key key, this.photoWall}) : super(key: key);
  @override
  _SlideBannerState createState() => _SlideBannerState();
}

class _SlideBannerState extends State<SlideBanner> {

  List<String> list = [];

  //自定圆点分页指示器
  buildSwiperPagination() {
    // 分页指示器
    return SwiperPagination(
      //指示器显示的位置
      alignment: Alignment.bottomRight, // 位置 Alignment.bottomCenter 底部中间
      // 距离调整
      margin: const EdgeInsets.fromLTRB(0, 0, 16, 10),
      // 指示器构建
      builder: DotSwiperPaginationBuilder(
        // 点之间的间隔
          space: 2,
          // 没选中时的大小
          size: 7,
          // 选中时的大小
          activeSize: 7,
          // 没选中时的颜色
          color: Color(0xfff3f3f3),
          //选中时的颜色
          activeColor: Color(0xff0c0c0c),
      )
    );
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getBanner();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      height: 355.0,
      child: new Swiper(
        // 横向
        scrollDirection: Axis.horizontal,
        // 布局构建
        itemBuilder: (BuildContext context, int index) {
          return Padding(padding: EdgeInsets.all(6.0),
            child: Container(
              //设置背景图片
              decoration: new BoxDecoration(
                // color: Colors.grey,
                // border: new Border.all(width: 2.0, color: Colors.red),
                borderRadius: new BorderRadius.all(Radius.circular(10.0)),
                image: new DecorationImage(
                  image: new NetworkImage(list[index]),
                  fit: BoxFit.cover
                ),
              ),
            ),
          );
        },
        //条目个数
        itemCount: list.length,
        // 自动翻页
        autoplay: true,
        // 分页指示
        pagination: buildSwiperPagination(),
        //点击事件
        onTap: (index) {
          print(" 点击 " + index.toString());
        },
        // 视窗比例
        viewportFraction: 1,
        // 布局方式
        //layout: SwiperLayout.STACK,
        // 用户进行操作时停止自动翻页
        autoplayDisableOnInteraction: true,
        //分页
        // 无线轮播
        loop: true,
        scale: 1, //
      ),
    );
  }

  void getBanner() {
    if(widget.photoWall != null){
      if(widget.photoWall.photo1 != '' && widget.photoWall.photo1 != null){
        list.add('http://119.28.131.94:82' + widget.photoWall.photo1);
      }
      if(widget.photoWall.photo2 != '' && widget.photoWall.photo2 != null){
        list.add('http://119.28.131.94:82' + widget.photoWall.photo2);
      }
      if(widget.photoWall.photo3 != '' && widget.photoWall.photo3 != null){
        list.add('http://119.28.131.94:82' + widget.photoWall.photo3);
      }
      if(widget.photoWall.photo4 != '' && widget.photoWall.photo4 != null){
        list.add('http://119.28.131.94:82' + widget.photoWall.photo4);
      }
      if(widget.photoWall.photo5 != '' && widget.photoWall.photo5 != null){
        list.add('http://119.28.131.94:82' + widget.photoWall.photo5);
      }
    }

  }




}

